﻿﻿﻿<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/html">
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
	      content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
	<meta http-equiv="Cache-Control" content="no-siteapp"/>
	<link href="${ctx}/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="${ctx}/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="${ctx}/css/animate.min.css" rel="stylesheet">
	<link href="${ctx}/css/labelauty.css" rel="stylesheet"/>
	<link href="${ctx}/css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="${ctx}/css/paper-person.css?v=4.85" rel="stylesheet">
	<title>人工组卷</title>
</head>
<body class="gray-bg">
<input type="hidden" id="basePath" value="${ctx}">
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-md-12">
			<div class="col-md-6">
				<span class="text-center" id="title"><h3>第一站问答试卷</h3> </span>
				<hr/>
				<form class="form-horizontal" id="examList">
					<div class="form-group">
						<input type="hidden" id="paperId" value="${paper.id}">
						<label class="control-label col-sm-2">站类型</label>
						<div class="col-sm-3">
							<select name="pattern" id="pattern" class="form-control" onchange="select()" disabled>
								<option value="WEN_DA">问答题</option>
								<option value="CHANG_GUI">常规化</option>
								<option value="KE_GUAN">客观化</option>
							</select>
						</div>
						<label class="control-label col-sm-2">试卷类型</label>
						<div class="col-sm-2">
							<select id="paperType" class="form-control" disabled>
								<option value="A">A</option>
								<option value="B">B</option>
							</select>
						</div>
						<label id="count" class="control-label col-sm-3"></label>
					</div>
					<div class='panel panel-default'>
						<div class='panel-heading'>
							<a data-toggle="collapse" style="float: right;margin: 10px auto " class="collapse-link"
							   href="#collapseOne">
								<i class="fa fa-chevron-up"></i>
							</a>
							<input type="radio" name="examType" id="examType1" class="rdolist" checked="checked"/>
							<label class="rdobox">
								<span class="check-image"></span>
								<span class="radiobox-content" id="exam1title">第一题:穴位定位</span>
							</label>
							<lable style="font-size:14px;" class='badge pull-right text-primary'
							       id='exam1count'></lable>
						</div>
						<div id="collapseOne" class="panel-collapse collapse in">
							<div class='panel-body'>
								<ul id="exam1"></ul>
							</div>
						</div>
					</div>
					<div class='panel panel-default'>
						<div class='panel-heading'>
							<a data-toggle="collapse" style="float: right;margin: 10px auto " class="collapse-link"
							   href="#collapseTwo">
								<i class="fa fa-chevron-up"></i>
							</a>
							<input type="radio" name="examType" id="examType2" class="rdolist"/>
							<label class="rdobox">
								<span class="check-image"></span>
								<span class="radiobox-content" id="exam2title">第二题:问答题</span>
							</label>
							<lable style="font-size:14px;" class='badge pull-right text-primary'
							       id='exam2count'></lable>
						</div>
						<div id="collapseTwo" class="panel-collapse collapse in">
							<div class='panel-body'>
								<ul id="exam2"></ul>
							</div>
						</div>
					</div>
					<div class='panel panel-default'>
						<div class='panel-heading'>
							<a data-toggle="collapse" style="float: right;margin: 10px auto " class="collapse-link"
							   href="#collapseThree">
								<i class="fa fa-chevron-up"></i>
							</a>
							<input type="radio" name="examType" id="examType3" class="rdolist"/>
							<label class="rdobox">
								<span class="check-image"></span>
								<span class="radiobox-content" id="exam3title">第三题:问答题</span>
							</label>
							<lable style="font-size:14px;" class='badge pull-right text-primary'
							       id='exam3count'></lable>
						</div>
						<div id="collapseThree" class="panel-collapse collapse in">
							<div class='panel-body'>
								<ul id="exam3"></ul>
							</div>
						</div>
					</div>

					<br/>
					<div class="form-group text-center">
						<a type="button" onclick="update_paper()" class="btn btn-primary">修改
						</a>
						<a type="button" onclick="clear_exam()" class="btn btn-default">重置</a>
					</div>
				</form>
			</div>
			<div class="col-md-6">
				<div class="text-center">
					<span><h3>从题库中筛选试题加入到当前试卷</h3> </span>
				</div>
				<hr/>
				<div class="row">
					<div class="col-sm-3">
						<select class="form-control" id="examClass" onchange="getCategory()">
							<option value="-1">全部</option>
                        <#list examClass as ec>
							<option value="${ec.id}">${ec.name}</option>
                        </#list>
						</select>
					</div>
					<div class="col-sm-3">
						<select class="form-control" id="category">
							<option value="-1">全部</option>
						</select>
					</div>
					<div class="col-sm-4">
						<input type="text" id="keywords" class="form-control" name="keywords" placeholder="请输入关键字...">
					</div>
					<div class="col-sm-2">
						<a class="btn btn-primary" onclick="searchExamList()">
							<i class="glyphicon glyphicon-search"></i>搜索
						</a>
					</div>
				</div>


				<div class="panel-group" id="accordion">
					<ul>
					</ul>
				</div>
				<div class="text-center">
					<div id="paginator">
					</div>
				</div>

			</div>
		</div>
	</div>
	<script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
	<script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
	<script src="${ctx}/js/content.min.js?v=1.0.0"></script>
	<script src="${ctx}/js/plugins/layer/layer.js"></script>
	<script src="${ctx}/js/bootstrap-paginator.js"></script>
	<script src="${ctx}/js/labelauty.js"></script>
	<script src="${ctx}/js/ddsort.js"></script>
	<script type="text/javascript">
		$('ul').DDSort({
			target: 'li',
			floatStyle: {
				'border': '1px solid #ccc',
				'background-color': '#fff'
			}
		});
		$(function () {
			$(".rdolist").labelauty("rdolist", "rdo");
			searchExamList(1);
			var paperId = $("#paperId").val();
			$.ajax({
				url: "${ctx}/person/update",
				data: {"paperId": paperId},
				dataType: "JSON",
				type: "GET",
				success: function (data) {
					var pattern = data.paper.paperPattern;
					var type = data.paper.type;
					if (pattern == "问答题") {
						$("#title").html("<h3>第一站问答试卷</h3>");
						$("#exam1title").text("第一题:腧穴题");
						$("#exam2title").text("第二题:问答题");
						$("#exam3title").text("第三题:问答题");
						$("#pattern").val("WEN_DA");
						$("#exam1").html("<li class='bg-success col-md-12' examId=" + data.exam1.id + "><div><a href='#' onclick=exam_detail('" + data.exam1.id + "')>" + data.exam1.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
						$("#exam2").html("<li class='bg-success col-md-12' examId=" + data.exam2.id + "><div><a href='#' onclick=exam_detail('" + data.exam2.id + "')>" + data.exam2.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
						$("#exam3").html("<li class='bg-success col-md-12' examId=" + data.exam3.id + "><div><a href='#' onclick=exam_detail('" + data.exam3.id + "')>" + data.exam3.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");

					} else if (pattern == "常规化") {
						$("#title").html("<h3>第二站常规化试卷</h3>");
						$("#exam1title").text("第一题:穴位定位");
						$("#exam2title").text("第二题:单项手法");
						$("#exam3title").text("第三题:成套手法");
						$("#pattern").val("CHANG_GUI");
						$(data.exam1).each(function (index, obj) {
							$("#exam1").append("<li class='bg-success col-md-12' examId=" + obj.id + " ><div><a href='#' onclick=exam_detail('" + obj.id + "')>" + obj.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
						})
						$(data.exam2).each(function (index, obj) {
							$("#exam2").append("<li class='bg-success col-md-12' examId=" + obj.id + " ><div><a href='#' onclick=exam_detail('" + obj.id + "')>" + obj.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
						})
						$("#exam3").html("<li class='bg-success col-md-12' examId=" + data.exam3.id + "><div><a href='#' onclick=exam_detail('" + data.exam3.id + "')>" + data.exam3.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");

					} else if (pattern == "客观化") {
						$("#title").html("<h3>第二站客观化试卷</h3>");
						$("#exam1title").text("第一题:穴位定位");
						$("#exam2title").text("第二题:单项手法");
						$("#exam3title").text("第三题:成套手法");
						$("#pattern").val("KE_GUAN");
						$(data.exam1).each(function (index, obj) {
							$("#exam1").append("<li class='bg-success col-md-12' examId=" + obj.id + " ><div><a href='#' onclick=exam_detail('" + obj.id + "')>" + obj.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
						})
						$(data.exam2).each(function (index, obj) {
							$("#exam2").append("<li class='bg-success col-md-12' examId=" + obj.id + " ><div><a href='#' onclick=exam_detail('" + obj.id + "')>" + obj.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
						})
						$("#exam3").html("<li class='bg-success col-md-12' examId=" + data.exam3.id + "><div><a href='#' onclick=exam_detail('" + data.exam3.id + "')>" + data.exam3.stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");

					}
					$("#paperType").val(type);
				}

			})

		});

		function searchExamList(page) {
			var text = "";
			var categoryId = $("#category").val();
			var keywords = $("#keywords").val();
			$.ajax({
				url: '${ctx}/person/examList',
				data: {"categoryId": categoryId, "currPage": page, "keywords": keywords},
				type: "POST",
				success: function (data) {
					$(data.examList).each(function (index, obj) {
						text += "<li class='bg-success'><a href='#' onclick=exam_detail('" + obj.id + "')>" + obj.stem + "<a><a href='#' onclick=add(this,'" + obj.id + "','" + obj.stem + "') class='pull-right'>" +
								"<i class='glyphicon glyphicon-plus'></i></a></li>";
					})

					$("#accordion").html(text);
					var options = {
						currentPage: page,
						totalPages: data.totalPage,
						numberOfPages: 5,
						onPageClicked: function (event, originalEvent, type, page) {
							searchExamList(page)
						}
					};
					$("#paginator").bootstrapPaginator(options);
				}

			});
		}

		function getCategory() {
			var id = $("#examClass").val();
			var text = "";
			if (id == "-1") {
				$("#category").empty();
				$("#category").html("<option value='-1'>全部</option>");
				return;
			}
			$.ajax({
				url: '${ctx}/paper/exam/category',
				data: {"id": id},
				dataType: "JSON",
				type: "GET",
				success: function (data) {
					$(data).each(function (index, obj) {
						text += "<option value='" + obj.id + "'>" + obj.name + "</option>";
					})
					$("#category").html(text);
				}

			})
		}

		function exam_detail(id) {
			layer.open({
				title: '试卷详情',
				type: 2,
				area: ['1000px', '500px'],
				shadeClose: true, //点击遮罩关闭
				content: '${ctx}/exam/examManage/detail/exam/' + id
			});
		}


		function add(obj, examId, stem) {
			var pattern = $("#pattern").val();
			var exam1Num = $("#exam1 li").size();
			var exam2Num = $("#exam2 li").size();
			var exam3Num = $("#exam3 li").size();
			var check1 = $("#examType1").is(':checked');
			var check2 = $("#examType2").is(':checked');
			var check3 = $("#examType3").is(':checked');
			if (pattern == "WEN_DA") {
				if (exam1Num == 0 && check1) {
					$("#exam1").append("<li class='bg-success col-md-12' examId=" + examId + "><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
				if (exam2Num == 0 && check2) {
					$("#exam2").append("<li class='bg-success col-md-12' examId=" + examId + "><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
				if (exam3Num == 0 && check3) {
					$("#exam3").append("<li class='bg-success col-md-12' examId=" + examId + "><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
			}
			if (pattern == "CHANG_GUI") {
				if (exam1Num < 5 && check1) {
					$("#exam1").append("<li class='bg-success col-md-12' examId=" + examId + " ><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
				if (exam2Num < 4 && check2) {
					$("#exam2").append("<li class='bg-success col-md-12' examId=" + examId + " ><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
				if (exam3Num == 0 && check3) {
					$("#exam3").append("<li class='bg-success col-md-12' examId=" + examId + "><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
			}

			if (pattern == "KE_GUAN") {
				if (exam1Num < 10 && check1) {
					$("#exam1").append("<li class='bg-success col-md-12' examId=" + examId + "><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
				if (exam2Num < 4 && check2) {
					$("#exam2").append("<li class='bg-success col-md-12' examId=" + examId + "><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
				if (exam3Num == 0 && check3) {
					$("#exam3").append("<li class='bg-success col-md-12' examId=" + examId + "><div><a href='#' onclick=exam_detail('" + examId + "')>" + stem + "</a></div><a href='#' onclick='remove(this)' class='pull-right'><i class='glyphicon glyphicon-remove'></i></a></li>");
					$(obj).closest("li").remove();
					return;
				}
			}
		}

		function remove(obj) {
			$(obj).closest("li").remove();
		}

		//修改试卷
		function update_paper() {
			var paperId = $("#paperId").val();
			var pattern = $("#pattern").val();
			var paperType = $("#paperType").val();
			var exam1 = [];
			var exam2 = [];
			var exam3 = [];
			$("#exam1 li").each(function () {
				exam1.push($(this).attr("examId"));
			});
			$("#exam2 li").each(function () {
				exam2.push($(this).attr("examId"));
			});
			$("#exam3 li").each(function () {
				exam3.push($(this).attr("examId"));
			});
			if (exam1 == null || exam1 == '' || exam2 == null || exam2 == '' || exam3 == null || exam3 == '') {
				layer.alert('请选择试题!', {
					icon: 5,
					skin: 'layer-ext-moon'
				})
				return;
			}
			//判断试题数量是否添加正确
			if (pattern == "WEN_DA") {
				if (exam1.length != 1 || exam2.length != 1 || exam3.length != 1) {
					layer.alert('请按照组卷策略试题数量添加!', {
						icon: 5,
						skin: 'layer-ext-moon'
					})
					return;
				}
			} else if (pattern == "CHANG_GUI") {
				if (exam1.length != 5 || exam2.length != 4 || exam3.length != 1) {
					layer.alert('请按照组卷策略试题数量添加!', {
						icon: 5,
						skin: 'layer-ext-moon'
					})
					return;
				}
			} else if (pattern == "KE_GUAN") {
				if (exam1.length != 10 || exam2.length != 4 || exam3.length != 1) {
					layer.alert('请按照组卷策略试题数量添加!', {
						icon: 5,
						skin: 'layer-ext-moon'
					})
					return;
				}
			}
			data = {
				"exam1": exam1,
				"exam2": exam2,
				"exam3": exam3,
				"pattern": pattern,
				"paperType": paperType,
				"paperId": paperId
			}
			$.ajax({
				url: "${ctx}/person/update",
				type: "PUT",
				data: data,
				cache: false,
				traditional: true,
				success: function (data) {
					var result = data.status;
					if (result == "401") {
						layer.alert('您没有权限!', {
							icon: 4,
							skin: 'layer-ext-moon'
						})
					} else if (result == "200") {
						layer.alert('修改成功!', {
							icon: 1,
							skin: 'layer-ext-moon'
						}, function () {
							setTimeout(function () {
								window.location.reload();
							}, 500);
						})
					} else if (result == "1001") {
						layer.alert('第一题未按照组卷策略添加!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "1002") {
						layer.alert('第一题已经在其他试卷中使用过!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "1003") {
						layer.alert('第二题未按照组卷策略添加!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "1004") {
						layer.alert('第二题该分类下的试题数量已足够，不能再次使用该分类下的试题进行组卷!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "1005") {
						layer.alert('第三题未按照组卷策略添加!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "1006") {
						layer.alert('第三题该分类下的试题数量已足够，不能再次使用该分类下的试题进行组卷!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "1007") {
						layer.alert('第二题已经在其他试卷中使用过!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "1008") {
						layer.alert('第三题已经在其他试卷中使用过!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2001") {
						layer.alert('第一题未按照组卷策略添加！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2002") {
						layer.alert('第一题不能添加重复的试题！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2004") {
						layer.alert('第一题成人穴位不能添加相同的部位的试题！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2005") {
						layer.alert('第一题成人穴位不能添加相同的经络的试题！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2006") {
						layer.alert('第一题儿科穴位不能添加相同的经络的试题！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2007") {
						layer.alert('第二题未按照组卷策略添加！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2008") {
						layer.alert('第二题不能添加重复的试题！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2009") {
						layer.alert('第二题不能添加相同大类的手法！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2010") {
						layer.alert('第三题未按照组卷策略添加！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2011") {
						layer.alert('第三题该分类下的试题数量已足够，不能再次使用该分类下的试题进行组卷！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "2012") {
						layer.alert('第三题已经在其他试卷中使用过！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3001") {
						layer.alert('第一题未按照组卷策略添加！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3002") {
						layer.alert('第一题成人穴位部位顺序不正确！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3003") {
						layer.alert('第一题成人穴位不能为相同经络！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3004") {
						layer.alert('第一题成人穴位不能添加相同试题！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3005") {
						layer.alert('第二题未按照组卷策略添加！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3006") {
						layer.alert('第二题单项手法不能添加相同大类的手法！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3007") {
						layer.alert('第二题不能添加相同的试题！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3008") {
						layer.alert('第二题未按照组卷策略添加！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3009") {
						layer.alert('第三题未按照组卷策略添加！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3010") {
						layer.alert('第三题该分类下的试题数量已足够，不能再次使用该分类下的试题进行组卷！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else if (result == "3011") {
						layer.alert('第三题已经在其他试卷中使用过！', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					} else {
						layer.alert('未知错误，请联系管理员!', {
							icon: 5,
							skin: 'layer-ext-moon'
						})
					}

				}
			})
		}

		function clear_exam() {
			$("#exam1").empty();
			$("#exam2").empty();
			$("#exam3").empty();
		}
	</script>
</body>
</html>